package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.OrdersAddress;
import com.qinggeng.project.system.service.IOrdersAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单地址Controller
 *
 * @author qinggeng
 * @date 2020-06-17
 */
@RestController
@RequestMapping("/system/orderAddress")
public class OrdersAddressController extends BaseController {
    @Autowired
    private IOrdersAddressService ordersAddressService;

    /**
     * 查询订单地址列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdersAddress ordersAddress) {
        startPage();
        List<OrdersAddress> list = ordersAddressService.selectOrdersAddressList(ordersAddress);
        return getDataTable(list);
    }

    /**
     * 导出订单地址列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "订单地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrdersAddress ordersAddress) {
        List<OrdersAddress> list = ordersAddressService.selectOrdersAddressList(ordersAddress);
        ExcelUtil<OrdersAddress> util = new ExcelUtil<OrdersAddress>(OrdersAddress.class);
        return util.exportExcel(list, "address");
    }

    /**
     * 获取订单地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{ordersAddressId}")
    public AjaxResult getInfo(@PathVariable("ordersAddressId") Long ordersAddressId) {
        return AjaxResult.success(ordersAddressService.selectOrdersAddressById(ordersAddressId));
    }

    /**
     * 根据订单编号获取订单位置详情
     */
    @GetMapping("/addressDetil/{orderId}")
    public AjaxResult addressDetil(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(ordersAddressService.selectOrdersAddressByOrdersId(orderId));
    }

    /**
     * 新增订单地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "订单地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdersAddress ordersAddress) {
        return toAjax(ordersAddressService.insertOrdersAddress(ordersAddress));
    }

    /**
     * 修改订单地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "订单地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdersAddress ordersAddress) {
        return toAjax(ordersAddressService.updateOrdersAddress(ordersAddress));
    }

    /**
     * 删除订单地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "订单地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ordersAddressIds}")
    public AjaxResult remove(@PathVariable Long[] ordersAddressIds) {
        return toAjax(ordersAddressService.deleteOrdersAddressByIds(ordersAddressIds));
    }
}
